//
//  XGLTabbarPlusButton.swift
//  XGamesLive
//
//  Created by ios on 2024/5/20.
//

import UIKit
import CYLTabBarController

class XGLTabbarPlusButton: CYLPlusButton,CYLPlusButtonSubclassing {

    static func plusButton() -> Any {
        let button = XGLTabbarPlusButton()
        button.setImage(imageWithName("img_xgl_tabbar_publish"), for: .normal)
        button.frame = CGRect(x: 0, y: 0, width: 50.0, height: 50.0)
        button.addTarget(self, action: #selector(testClick(sender:)), for: .touchUpInside)
        return button
    }

    @objc static func testClick(sender: UIButton){
        guard let window = UIApplication.shared.currentWindow else { return  }
        let alertView = PersonalPublishAlertView()
        alertView.showPickerView()
        window.addSubview(alertView)
        alertView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
    }

    static func indexOfPlusButtonInTabBar() -> UInt {
        return 2
    }

    static func multiplier(ofTabBarHeight _: CGFloat) -> CGFloat {
        return 0.3
    }

    static func constantOfPlusButtonCenterYOffset(forTabBarHeight _: CGFloat) -> CGFloat {
        return -10
    }

//    static func plusChildViewController() -> UIViewController {
//        let vc = PublishViewController()
//        let nav = XGLNavigationController(rootViewController: vc)
//        return nav
//    }

    static func shouldSelectPlusChildViewController() -> Bool {
        return true
    }

    override func layoutSubviews() {
        super.layoutSubviews()

        // tabbar UI layout setup
        let imageViewEdgeWidth: CGFloat = bounds.size.width  * 0.8
        let imageViewEdgeHeight: CGFloat = imageViewEdgeWidth

        let centerOfView = bounds.size.width * 0.5
        let labelLineHeight = titleLabel!.font.lineHeight
        let verticalMargin = (bounds.size.height - labelLineHeight - imageViewEdgeHeight) * 0.5

        let centerOfImageView = 12.0 + imageViewEdgeHeight * 0.5
        // imageView position layout
        imageView!.bounds = CGRect(x: 0, y: 0, width: imageViewEdgeWidth, height: imageViewEdgeHeight)
        imageView!.center = CGPoint(x: centerOfView, y: centerOfImageView)

    }

}
